using MallApi.Common;
using MallApi.DTOs.Requests;
using Microsoft.AspNetCore.Mvc;
using Services;

namespace MallApi.Controllers;

[ApiController]
[Route("api_v2/user")]
public class UserController : Controller
{
  private readonly IUserService _userService;

  public UserController(IUserService userService)
  {
    _userService = userService;
  }

  [HttpPost("login")]
  public async Task<ApiResult<object>> Login([FromBody] LoginRequest request)
  {
    // 验证手机号码和验证码
    // 生成token
    var data = new
    {
      user = await _userService.GetUserByMobile(request.Mobile),
      mobile = request.Mobile,
      code = request.Code
    };

    return ApiResult<object>.Success(data);
  }
}